/**
 * @file NETWORK.h
 *
 * @ingroup	libNetwork
 * @brief	Transport and Routing protocols, Public interface
 * 
 * @author	Andreas Schlueter <mersaultpatrice@gmail.com>
 * @date	Mar 2008
 * @version	0.5
 */

#ifndef NETWORK_H
#define NETWORK_H

#include <ScatterWeb.System.h>
#include <Infrasound.VDM.h>

#define NETWORK_MAX_DESTINATIONS 10 ///<amount of e.g. maximal cost table entries

/**
 * dialog messages
 */
enum dialog_message{
	MSG_VOTE,
	MSG_ACTIVITY,
	MSG_DEMAND
};

/**
 * @brief	message handler callback (application layer)
 *
 * @para msg message to be handled
 * @return false, if msg has to be handled by another msgHandler
 */
typedef bool(*fp_message_handler)(enum dialog_message msg);

/**
 * @brief adds new apllication message handler
 *
 * @param mh callback function of application layer handles incoming messages
 *
 * @return 0 if success
 */
uint8_t network_addMessageHandler(fp_message_handler mh);

/**
 * @brief broadcasts a dialog message
 *
 * @param msg message to be broadcasted
 *
 * @return 0 if success
 */
uint8_t network_shout(enum dialog_message msg);

/**
 * @brief initializes the network layer
 *
 * @return 0 if success
 */
uint8_t network_init();

//#ifdef DATA_SINK
/**
 * @brief	network_send callback function for application layer (gateway)
 */
typedef void(*fp_network_cb)(uint8_t size, uint8_t* data);

/**
 * @brief initiates data-centric interest propagation
 *
 * @param cb callback function handles new data. data becomes invalid after call.
 * @return 0 if success
 */
uint8_t network_data_interest(fp_network_cb cb);
//#endif

//#ifndef DATA_SINK
/**
 * @brief sends a datablock to gateway node
 *	A CRC is computed for each frame in block and the block is released to VDM
 *  until earliest the next TX_DATA slot
 *
 * @param block pointer to data block to sent
 *
 * @return 0 if success
 */
uint8_t network_send(sd_block_t* block);
//#endif

/**
 * @brief broadcasts message in network
 *
 * @param msg reference to message to be broadcasted
 *
 * @return 0 if success
 */
//uint8_t network_broadcast(struct message_t* msg);

/**
 * WARNING codes
 */
#define NETWORK_WARNING_DISTURBANCE     1 ///< possibly disturbance of neighbour nodes
#define NETWORK_WARNING_RETRANSMISSION  2
#define NETWORK_WARNING_DAT_DROPPED     3
#define NETWORK_WARNING_ADV_LOST        4

/**
 * ERROR return numbers
 */
#define NETWORK_ERROR_OUT_OF_MEMORY 1
#define NETWORK_ERROR_NO_CONNECTION 2
#define NETWORK_ERROR_BAD_TIME      3
#define NETWORK_ERROR_OUT_OF_SLOT   4
#define NETWORK_ERROR_PROTOCOL      5
#define NETWORK_ERROR_SYSTEM        6
#define NETWORK_ERROR_GENERAL       7
#define NETWORK_ERROR_ASYNCH		8

#endif


